import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/config/router_config.dart';
import 'package:s_mankey/generated/I18n.dart';

class HomeSort extends StatelessWidget {

  @override
  Widget build(BuildContext context) {

    ///生成多个icon
    List<Widget> items = [
      _setIcon(context: context,iconCode: 0xe64f, title: I18n.current.videoCource, urlIndex: 1),
      _setIcon(context: context,iconCode: 0xe679, title: I18n.current.company, urlIndex: 2),
      _setIcon(context: context,iconCode: 0xe656, title: I18n.current.community, urlIndex: 3),
      _setIcon(context: context,iconCode: 0xe64b, title: I18n.current.volunteer, urlIndex: 4),
    ];

    return Container(
      height: 90,
//      color: Colors.grey,
      child: GridView.builder(
        itemCount: items.length,
        padding: EdgeInsets.all(AppPadding.Padding10),
//        physics: NeverScrollableScrollPhysics(),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: items.length, //横轴4个子widget
//            childAspectRatio: items.length / items.length  //宽高比为1时，子widget
            ),
        itemBuilder: (BuildContext context, int index) {
          return items[index];
        },
      ),
    );
  }
}

///单个item
Widget _setIcon({BuildContext context,int iconCode, String title, int urlIndex}) {
  return GestureDetector(
    onTap: () {
      Navigator.of(context).pushNamed(RouterName.webView, arguments: title);
    },
    child: Column(
      children: <Widget>[
        Stack(
          alignment: AlignmentDirectional.center,
          children: <Widget>[
            Container(
              constraints: BoxConstraints(
                  maxHeight: 60, minHeight: 60, maxWidth: 60, minWidth: 60),
              decoration: BoxDecoration(
                color: AppColor.SerchBarColor,
                shape: BoxShape.circle,
              ),
              child: Icon(
                IconData(iconCode, fontFamily: IconFonts.fontFamily),
                size: AppCustomSize.IconDataSize,
                color: AppColor.btnNavBarIconColor,
              ),
            ),
          ],
        ),
        Text(title),
      ],
    ),
  );
}
